package com.wanmait.wisdom.manage.controller;

import com.wanmait.wisdom.entity.House;
import com.wanmait.wisdom.manage.service.ManageHouseService;
import com.wanmait.wisdom.util.AjaxResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("manage")
public class ManageHouseController{

    @Resource
    public ManageHouseService manageHouseService;

    @GetMapping("getUnsoldCount")
    public AjaxResult getUnsoldCount(){
        return AjaxResult.success(manageHouseService.getUnsoldCount());
    }
    @GetMapping("getRentOutCount")
    public AjaxResult getRentOutCount(){
        return AjaxResult.success(manageHouseService.getRentOutCount());
    }
    @GetMapping("getSoldOutCount")
    public AjaxResult getSoldOutCount(){
        return AjaxResult.success(manageHouseService.getSoldOutCount());
    }
    /**
     * 房屋分页列表
     * @param pageNum
     * @param pageSize
     * @return
     */
    @PostMapping("pageHouseList")
    public AjaxResult PageHouseList(@RequestBody(required = false) House house, Integer pageNum,Integer pageSize){
        return manageHouseService.listPage(house,pageNum,pageSize);
    }

    @PostMapping("pageHouseSearch")
    public AjaxResult PageHouseSearch(@RequestBody House house, Integer pageNum, Integer pageSize){
        return manageHouseService.searchPage(house,pageNum,pageSize);
    }
    @PostMapping("housesave")
    public AjaxResult save(@RequestBody House house){return manageHouseService.HouseAdd(house);}

    @PostMapping("blurNumber")
    public AjaxResult blurNumber(@RequestBody House house){return manageHouseService.blurNumber(house);}

    @GetMapping("selectHouseById")
    public AjaxResult selectHouseById(Integer id){
        if (id==null||id==0){
            return AjaxResult.error(0000,"id不能为空");
        }
        List<House> list = manageHouseService.selectHouseById(id);
        if (list!=null&&list.size()>0){
            return AjaxResult.success().put("house",list);
        }
        else{
            return AjaxResult.error(0000,"查询失败");
        }
    }

    @GetMapping("selectHouseByUnit")
    public AjaxResult selectHouseByUnit(House house){ return AjaxResult.success(manageHouseService.selectByUnitId(house));}
    @GetMapping("houseByid")
    public AjaxResult houseByid(Integer id){return manageHouseService.houseByid(id);}
}
